//
//  NoticeDetailCell.m
//  Notice
//
//  Created by CPX on 2018/9/13.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "NoticeDetailCell.h"

/**
 通知详情Cell
 */
@interface NoticeDetailCell()

@property (nonatomic,strong) UIImageView *bgView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) UILabel *dateLabel;

@end

@implementation NoticeDetailCell

- (void)setNotice:(NoticeModel *)notice{
    _notice = notice;
    self.bgView.hidden = NO;
    
    self.contentLabel.text = notice.body;
    self.dateLabel.text = notice.createDateFormatStr;
    if ([notice.event_type isEqualToString:@"system_notify"]) {
        self.titleLabel.text = notice.title;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        self.titleLabel.textColor = UIColorHex(#00732F);
    }
    else if([notice.event_type isEqualToString:@"comment"]){
        self.titleLabel.font = [UIFont systemFontOfSize:13];
        self.titleLabel.text = notice.pusher_name;
        self.titleLabel.textColor = UIColorHex(#001208);
    }
}

#pragma mark - lazy load

- (UIImageView*)bgView{
    if (!_bgView) {
        _bgView = [UIImageView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 5;
        _bgView.layer.masksToBounds = YES;
        _bgView.userInteractionEnabled = YES;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        //        UIImage *image = [[UIImage imageNamed:@"shadow_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 5, 8, 8) resizingMode:UIImageResizingModeStretch];
        //        _bgView.backgroundColor = [UIColor whiteColor];
        //        _bgView.image = image;
        [self.contentView addSubview:_bgView];
        self.contentView.backgroundColor = UIColorHex(#f4f4f4);
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(12);
            make.trailing.mas_equalTo(-12);
            make.top.mas_equalTo(16);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _bgView;
}

- (UILabel*)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = UIColorHex(#001208);
        _titleLabel.numberOfLines = 0;
        [self.bgView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.bgView).offset(12);
            make.leading.mas_equalTo(self.bgView).offset(12);
            make.trailing.mas_equalTo(self.bgView).offset(-12);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _titleLabel;
}

- (UILabel*)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [UILabel new];
        _contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.textColor = UIColorHex(#292929);
        _contentLabel.numberOfLines = 0;
        [self.bgView addSubview:_contentLabel];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.dateLabel.mas_bottom).offset(12);
            make.leading.mas_equalTo(self.bgView).offset(12);
            make.trailing.mas_equalTo(-12);
            make.height.mas_greaterThanOrEqualTo(10);
            make.bottom.mas_equalTo(self.bgView.mas_bottom).offset(-12);
        }];
    }
    return _contentLabel;
}

- (UILabel*)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [UILabel new];
        _dateLabel.font = [UIFont systemFontOfSize:11];
        _dateLabel.textColor = UIColorHex(#929292);
        _dateLabel.numberOfLines = 0;
        [self.bgView addSubview:_dateLabel];
        [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(3);
            make.leading.mas_equalTo(self.titleLabel);
            make.trailing.mas_equalTo(self.titleLabel);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _dateLabel;
}

@end
